import Box = Laya.Box;
import Sprite = laya.display.Sprite;
import UIImage = Laya.Image;
import Tween = laya.utils.Tween;
import Point = laya.maths.Point;
import Ease = laya.utils.Ease;
import List = laya.ui.List;
import Panel = laya.ui.Panel;
import Label = laya.ui.Label;
import Handler = laya.utils.Handler;
import Clip = laya.ui.Clip;
import Skeleton = Laya.Skeleton;
import Pool = Laya.Pool;

import GameFacade from "./GameFacade";
import GameEvent from "./constant/GameEvent";
import ProtoBuf from "./net/ProtoBuf";
import GameConfig from "./GameConfig";
import GameStart from "./game/GameStart";

class Main {
    constructor() {
        if (window["Laya3D"]) Laya3D.init(GameConfig.width, GameConfig.height);
        else Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
        Laya["Physics"] && Laya["Physics"].enable();
        Laya.stage.scaleMode = GameConfig.scaleMode;
        Laya.stage.screenMode = GameConfig.screenMode;

        //Laya.stage.bgColor = "#FF0000";
        //兼容微信不支持加载scene后缀场景
        Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;
        //打开调试面板（通过IDE设置调试模式，或者url地址增加debug=true参数，均可打开调试面板）
        if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true") Laya.enableDebugPanel();
        if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"]) Laya["PhysicsDebugDraw"].enable();
        if (GameConfig.stat) Laya.Stat.show();
        Laya.alertGlobalError = true;

        //发布dev  斗鱼需要屏蔽的
        Laya.URL.basePath = Laya.URL.rootPath = "";

        //激活资源版本控制，version.json由IDE发布功能自动生成，如果没有也不影响后续流程
        Laya.ResourceVersion.enable("gameVersion.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
        //Laya.Stat.show(0, 0);
        // 修改初始化内存
        window['Config3D'] && (window['Config3D']['_defaultConfig']['_defaultPhysicsMemory'] = 100);
        //调用DebugPanel调试面板
        //Laya.PhysicsDebugDraw.init();
    }
    onVersionLoaded(): void {
        //激活大小图映射，加载小图的时候，如果发现小图在大图合集里面，则优先加载大图合集，而不是小图
        Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
    }

    onConfigLoaded(): void {
        // //加载IDE指定的场景
        // GameConfig.startScene && Laya.Scene.open(GameConfig.startScene);
        new GameStart();
    }

}
new Main();